﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using log4net.Layout;

namespace SimpleInfrastructure.Log
{
    public class DefaultLogger:ILogger
    {
        private static readonly ILogger _instance = new DefaultLogger();

        public static ILogger Instance
        {
            get { return _instance; }
        }

        private DefaultLogger()
        {

        }

        public bool IsEnabled(LogLevel level)
        {
            switch (level)
            {
                case LogLevel.Debug:
                case LogLevel.Information:
                case LogLevel.Warning:
                    return Log4NetHelper.CanLogInfo;
                case LogLevel.Error:
                case LogLevel.Fatal:
                    return Log4NetHelper.CanLogError;
                default:
                    return false;
            }
        }

        public void Log(LogLevel level, Exception exception, string messageFormat, params object[] args)
        {
            switch (level)
            {
                case LogLevel.Debug:
                case LogLevel.Information:
                case LogLevel.Warning:
                    Log4NetHelper.Info(string.Format(messageFormat, args));
                    break;
                case LogLevel.Error:
                case LogLevel.Fatal:
                    Log4NetHelper.Error(string.Format(messageFormat, args), exception);
                    break;
                default:
                    break;
            }
        }

        public void Log(LogLevel level, string messageFormat, params object[] args)
        {
            switch (level)
            {
                case LogLevel.Debug:
                case LogLevel.Information:
                case LogLevel.Warning:
                    Log4NetHelper.Info(string.Format(messageFormat, args));
                    break;
                case LogLevel.Error:
                case LogLevel.Fatal:
                    Log4NetHelper.Error(string.Format(messageFormat, args));
                    break;
                default:
                    break;
            }
        }
    }
}
